/**
 * 
 */
package com.app.service.impl.ajaxservice;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.app.service.BaseService;
import com.app.service.IAjaxService;
import com.app.service.vo.UserVo;

/**
 * @author Administrator
 *
 */
public class UserLoginValidateImpl extends BaseService implements IAjaxService {

	/**
	 * 
	 */
	public UserLoginValidateImpl() {
	}

	/* (non-Javadoc)
	 * @see com.app.service.IAjaxService#validate(java.util.Map)
	 */
	@SuppressWarnings({  "unchecked" })
	@Override
	public Map<?, ?> execute(HttpServletRequest request) {
		Map<String,String> result = new HashMap<String,String>();
		if(request.getParameter("username").equals("admin"))
		{
			String pass = (String) this.getCacheService().getObject("admin");
			if(pass.equals(request.getParameter("password")))	
			{
				result.put("status", "ok");
				request.getSession().setAttribute("loginname", request.getParameter("username"));
			}else
			{
				result.put("status", "error");
				result.put("password", "密码错误!");
				result.put("username", "");
			}
			return result;
		}
		Map<String, UserVo> usermap = (Map<String, UserVo>) this.getCacheService().getObject("corn-uesr");
		UserVo vo = usermap.get(request.getParameter("username"));
		if(null!=vo)
		{
			if(vo.getPassword().equals(request.getParameter("password")))
			{
				result.put("status", "ok");
				request.getSession().setAttribute("loginname", request.getParameter("username"));
			}else
			{
				result.put("status", "error");
				result.put("password", "密码错误!");
				result.put("username", "");
			}
		}else 
		{
			result.put("status", "error");
			result.put("username", "用户名错误");
			result.put("password", "密码错误");
		}
		return result;
	}

}
